<template>
  <div style="margin-top: 50px">
    <el-form :model="value" ref="productSaleForm" label-width="120px" style="width: 600px" size="small">
      <el-form-item label="赠送积分：">
          <el-select v-model="value.gotScore" placeholder="请选择">
            <el-option
              v-for="item in JfOptions"
              :key="item.value"
              :label="item.label"
              :value="item.value">
            </el-option>
          </el-select>
      </el-form-item>

      <el-form-item label="商品上架：">
        <el-switch
          v-model="value.status"
          :active-value="1"
          :inactive-value="0">
        </el-switch>
      </el-form-item>
      <el-form-item label="商品推荐：">
        <el-switch
          v-model="value.recommendStatus"
          :active-value="1"
          :inactive-value="0">
        </el-switch>
      </el-form-item>
      <el-form-item label="是否秒杀：">
        <el-switch
          v-model="value.miaosha"
          :active-value="1"
          :inactive-value="0">
        </el-switch>
      </el-form-item>
      <el-form-item v-show="value.miaosha">
        <div>
          开始时间：
          <el-date-picker
            v-model="value.miaoshaoStartTime"
            value-format="timestamp"
            type="datetime"
            :picker-options="pickerOptions1"
            placeholder="选择开始时间">
          </el-date-picker>
        </div>
        <div class="littleMargin">
          结束时间：
          <el-date-picker
            v-model="value.miaoshaoEndTime"
            value-format="timestamp"
            type="datetime"
            :picker-options="pickerOptions1"
            placeholder="选择结束时间">
          </el-date-picker>
        </div>
       
      </el-form-item>

      <el-form-item style="text-align: center">
        <el-button size="medium" @click="handlePrev">上一步，填写商品属性</el-button>
        <el-button type="primary" size="medium" @click="handleFinishCommit">完成，提交商品</el-button>
      </el-form-item>

    </el-form>
  </div>
</template>

<script>
  import {fetchList as fetchMemberLevelList} from '@/api/memberLevel'

  export default {
    name: "ProductSaleDetail",
    props: {
      value: Object,
      isEdit: {
        type: Boolean,
        default: false
      }
    },
    data() {
      return {
        //日期选择器配置
        pickerOptions1: {
          disabledDate(time) {
            return time.getTime() < Date.now();
          }
        },
        JfOptions:[
          {
          value: 2,
          label: '一元2分'
        },{
          value: 1.5,
          label: '一元1.5分'
        }, {
          value: 1,
          label: '一元1分'
        }, {
          value: 0.8,
          label: '一元0.8分'
        }, {
          value: 0.5,
          label: '一元0.5分'
        }, {
          value: 0.1,
          label: '一元0.1分'
        },
        {
          value: 0,
          label: '无积分'
        }
        ]
      }
    },
    created() {
      if (this.isEdit) {
        
      } else {
        // fetchMemberLevelList({defaultStatus: 0}).then(response => {
        //   let memberPriceList = [];
        //   for (let i = 0; i < response.data.length; i++) {
        //     let item = response.data[i];
        //     memberPriceList.push({memberLevelId: item.id, memberLevelName: item.name})
        //   }
        //   this.value.memberPriceList = memberPriceList;
        // });
      }
    },
    methods: {
      handlePrev() {
        this.$emit('prevStep')
      },
      handleFinishCommit(){
        console.log(this.value.miaosha)
        if(this.value.miaosha){
           if(!this.value.miaoshaoStartTime || !this.value.miaoshaoEndTime){
              this.$message({
              message: '请设置秒杀开始和结束时间！',
              type: 'error',
              duration:1000
            });
            return
           }
        }
        this.$emit('finishCommit',this.isEdit);
      }
    }
  }
</script>

<style scoped>
  .littleMargin {
    margin-top: 10px;
  }
</style>
